package com.ecommerce.repository;

import com.ecommerce.entity.Banner;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BannerRepository extends JpaRepository<Banner, Long> {
    
    // 获取所有激活的轮播图，按排序顺序排列
    @Query("SELECT b FROM Banner b WHERE b.isActive = true ORDER BY b.sortOrder ASC, b.createdAt DESC")
    List<Banner> findActiveBannersOrderBySortOrder();
    
    // 获取主轮播图
    @Query("SELECT b FROM Banner b WHERE b.isActive = true AND b.isMain = true ORDER BY b.sortOrder ASC, b.createdAt DESC")
    List<Banner> findMainBanners();
    
    // 根据排序获取前N个轮播图
    @Query("SELECT b FROM Banner b WHERE b.isActive = true ORDER BY b.sortOrder ASC, b.createdAt DESC")
    List<Banner> findTopBanners();
} 